<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公司列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            姓名：<input type="text" name="name"/>
                        </li>
                        <li>
                            工号：<input type="text" name="badge"/>
                        </li>
                        <li>
                            在岗状态：<select name="status">
                            <option value="">全部</option>
                            <option value="0">在岗</option>
                            <option value="1">离职</option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:role:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <button class="btn btn-info" onclick="detail()"><i class="fa fa-search"></i> 查看</button>
            <button class="btn btn-success" onclick="add()"><i class="fa fa-plus"></i> 新增</button>
            <button class="btn btn-primary" onclick="edit()"><i class="fa fa-edit"></i> 修改</button>
            <button class="btn btn-danger" onclick="del()"><i class="fa fa-remove"></i> 删除</button>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="emp-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>


<script th:inline="javascript">
    var prefix = ctx + "jpbi/emp";

    $(function () {
        queryUserList();
    });

    function queryUserList() {
        var options = {
            id: "emp-table",
            uniqueId: "eid",
            code: "eid",
            url: prefix + "/getEmpList",
            createUrl: prefix + "/add",
            removeUrl: prefix + "/remove",
            detailUrl: prefix + "/detail",
            exportUrl: prefix + "/export",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            sortName: "eid",
            modalName: "人员信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'badge',
                    title: '工号',
                },
                {
                    field: 'compID',
                    title: '公司ID',
                },
                {
                    field: 'depID',
                    title: '部门ID',
                },
                {
                    field: 'jobID',
                    title: '岗位ID',
                },
                {
                    field: 'reportTo',
                    title: '上级领导',
                },
                {
                    field: 'empStatus',
                    title: '在岗状态',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs"  onclick="Comporg(\'' + row.compID + '\')">查看所在公司组织机构</a> ');
                        actions.push('<a class="btn btn-info btn-xs" onclick="Deporg(\'' + row.depID + '\')">查看所在公司组织机构</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function add() {
        $.operate.add();
    }

    function edit() {
        var row = $("#emp-table").bootstrapTable('getSelections');
        var num = 0;
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择需要修改的人员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            $.operate.edit_currency(row[i].eid, row[i].name, "/jpbi/emp/editEmp","xiao");
        }
    }

    function del() {
        var row = $("#emp-table").bootstrapTable('getSelections');
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择需要离职的人员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allEid += row[i].eid
            } else {
                allEid += row[i].eid + ","
            }
        }
        $.ajax({
            async: false,
            url: "/jpbi/emp/remove",
            data: {
                "allEid": allEid,
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#emp-table").bootstrapTable('refresh');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function detail() {
        var row = $("#emp-table").bootstrapTable('getSelections');
        var num = 0;
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择需要查看的人员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            $.operate.detail_currency(row[i].eid, row[i].name, "/jpbi/emp/detail","xiao");
        }
    }

    function Comporg(compID){
        alert(compID);
    }

    function Deporg(depID){
        alert(depID);
    }

</script>
</body>
</html>